package com.tiancheng.trade.payment.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.tiancheng.trade.payment.bo.SettleFlowDetailMerchantBO;
import com.tiancheng.trade.payment.channel.bo.UnifiedOrderSettleBO;
import com.tiancheng.trade.payment.enums.WithdrawalStatusEnum;
import com.tiancheng.trade.payment.model.PaymentFlowDetail;
import com.tiancheng.trade.payment.model.PaymentFlowDetailSettle;
import com.tiancheng.trade.payment.model.PaymentOrder;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;

/**
 * @ClassName PaymentFlowDetailSettleService
 * @Description 支付明细结算信息 service
 * @Author kellen
 * @Date 2024/11/28 21:51
 */
public interface PaymentFlowDetailSettleService extends IService<PaymentFlowDetailSettle> {
    /**
     * 根据自流水号查询
     *
     * @param flowId     支付流水号
     * @param subFlowIds 子支付流水号
     * @return
     */
    List<PaymentFlowDetailSettle> queryBySubFlowIds(String flowId, Set<String> subFlowIds);

    /**
     * 生成结算信息
     * @param paymentOrder 支付流水
     * @param flowDetails 支付流水明细
     * @param subSettles 计算流水明细
     * @return
     */
    boolean genSettle(PaymentOrder paymentOrder,List<PaymentFlowDetail> flowDetails, List<UnifiedOrderSettleBO> subSettles);


    /**
     * 聚合应清分商户、商品编码
     *
     * @param expectSettleDate 渠道应核销日期
     * @return
     */
    List<SettleFlowDetailMerchantBO> distinctSettleMerchant(LocalDate expectSettleDate, String payChannel);

    IPage<PaymentFlowDetailSettle> listWaitSettles(LocalDate expectSettleDate, String payChannel, long current, long size);

    boolean withdrawResult(String withdrawalId, WithdrawalStatusEnum withdrawalStatusEnum, LocalDateTime transTime);

    /**
     * 等待结算的交易流水
     * 所有子订单流水都已经核销
     * @param payChannel 支付通道
     * @return
     */
    List<PaymentFlowDetailSettle> waitSettleAccountsFlows(String payChannel);
}
